//
//  AppDelegate.swift
//  YLPaymentDemo
//
//  Created by changhe on 2025/4/12.
//

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // 初始化支付服务时已自动注册配置的支付模块
        // 不再需要手动注册各模块
        YLPaymentService.shared.setup()
        return true
    }

    // MARK: - URL处理
    
    // 处理URL回调（iOS 9.0+）
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        // 将URL传递给支付服务处理
        return YLPaymentService.shared.handleOpenURL(url)
    }
    
    // 处理Universal Links（iOS 9.0+）
    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        // 如果是Universal Link，传递给支付服务处理
        if userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL {
            return YLPaymentService.shared.handleOpenUniversalLink(url)
        }
        return false
    }
}

